﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LCA.Community.DAL.Model;
using LCA.Community.DAL.Interfaces;

namespace LCA.Community.DAL
{
    /// <summary>
    /// The repository for help relationships data manipulation.
    /// </summary>
    public class HelpRelationshipsRepository : BaseRepository<HelpRelationship>, IHelpRelationshipsRepository
    {
        #region Fields

        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="HelpRelationshipsRepository"/> class.
        /// </summary>
        /// <param name="dataServiceContext">The data service context.</param>
        /// <param name="usersRepository">The users repository.</param>
        public HelpRelationshipsRepository(IDataServiceContext<HelpRelationship> dataServiceContext)
            :base(dataServiceContext)
        {

        }

        /// <summary>
        /// Gets the help relationships by user.
        /// </summary>
        /// <param name="userID">The user ID.</param>
        /// <returns></returns>
        public List<HelpRelationship> GetHelpRelationshipsByUser(string userID)
        {
            var hrs = (from hr in Entities
                        where hr.User == userID || hr.Volunteer == userID
                        select hr).ToList();

            return hrs;
        }

        /// <summary>
        /// Deletes all user help relationships.
        /// </summary>
        /// <param name="userID">The user ID.</param>
        public void DeleteAllUserHelpRelationships(string userID)
        {
            var hrs = GetHelpRelationshipsByUser(userID);

            hrs.ForEach(hr => Delete(hr));
        }
    }
}
